﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace StockholmsStad.Windows.UI.Infrastructure.Converters
{
    public class DateTimeToDateTimeString : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType != typeof(string))
                throw new InvalidOperationException("The target must be a string");

            if (value != null)
            {
                var dateTime = (DateTime)value;
                return dateTime.ToString("yyyy-MM-dd HH:mm");
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
